package cn.edu.cqvie.jdk8.fun;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.function.Predicate;

public class PredicateTest2 {

    public static void main(String[] args) {

        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

        PredicateTest2 predicateTest2 = new PredicateTest2();

        //打印偶数
        predicateTest2.conditionFilter(list, item -> item % 2 == 0);

        System.out.println("--------------");
        //打印奇数
        predicateTest2.conditionFilter(list, item -> item % 2 == 1);

        System.out.println("--------------");
        //打印>5
        predicateTest2.conditionFilter(list, item -> item > 5);

        System.out.println("--------------");
        //打印<3
        predicateTest2.conditionFilter(list, item -> item < 3);

        System.out.println("--------------");
        //打印所有
        predicateTest2.conditionFilter(list, item -> true);

        System.out.println("--------------");
        //不打印任何数字
        predicateTest2.conditionFilter(list, item -> false);


        System.out.println("--------------");
        //打印偶数 and >5
        predicateTest2.conditionFilter2(list, item -> item > 5, item -> item % 2 == 0);

        System.out.println("--------------");
//        Date date = new Date();
        System.out.println(predicateTest2.isEqual(new Date()).test(new Date()));
    }


    /**
     * 过滤
     * @param list 处理数据
     * @param predicate 处理行为
     */
    public  void  conditionFilter(List<Integer> list, Predicate<Integer> predicate) {
        for (Integer integer : list) {
            if (predicate.test(integer)) {
                System.out.println(integer);
            }
        }
    }


    /**
     * 过滤
     * @param list 处理数据
     * @param predicate 处理行为
     */
    public void conditionFilter2(List<Integer> list, Predicate<Integer> predicate,
                                 Predicate<Integer> predicate2
    ) {
        for (Integer integer : list) {
            if (predicate.and(predicate2).test(integer)) {
                System.out.println(integer);
            }
        }
    }

    public Predicate<Date> isEqual(Object object) {
        return Predicate.isEqual(object);
    }

//    public void  finAllOdds() {
//
//    }
//
//    public  void findAllEven(List<Integer> list) {
//
//    }

}
